package com.daxia.ogmall.web.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.daxia.ogmall.dto.CityDTO;
import com.daxia.ogmall.model.Province;

@Controller
@RequestMapping("province")
public class ProvinceController extends BaseController {

	@ResponseBody
    @RequestMapping("findArea")
    public String findArea(Long provinceId, Long cityId) throws Exception {
        if (provinceId != null) {
            CityDTO query = new CityDTO();
            query.setProvince(new Province());
            query.getProvince().setId(provinceId);
            List<CityDTO> cities = cityService.find(query, null);
            JSONArray array = new JSONArray();
            for (CityDTO d : cities) {
                JSONObject json = new JSONObject();
                json.put("id", d.getId());
                json.put("name", d.getName());
                array.add(json);
            }
            return array.toJSONString();
        }
        return null;
    }
	
	
}	
